package com.jinzhi.jzweb.controller.moduleConfig;


import java.util.*;

import com.jinzhi.api.exception.IFastApiException;
import com.jinzhi.common.type.ApiEnumError;
import com.jinzhi.jzweb.dao.CareStuSignUpComRealityDao;
import com.jinzhi.jzweb.domain.StuSignUpComDO;
import com.jinzhi.jzweb.domain.moduleConfig.DecryptDO;
import com.jinzhi.jzweb.domain.moduleConfig.TrackDrawDO;
import com.jinzhi.jzweb.service.moduleConfig.TrackDrawService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * <pre>
 * 赛道抽签表（存储抽签信息）
 * </pre>
 * <small> 2024-02-28 09:32:18 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/trackDraw")
@Api(value = "抽签管理", tags = {"抽签管理"})
public class TrackDrawController extends BaseController {
	@Autowired
	private TrackDrawService trackDrawService;
	@Autowired
	private CareStuSignUpComRealityDao careStuSignUpComRealityDao;
	
	@GetMapping()
	String TrackDraw(){
	    return "jzweb/trackDraw/trackDraw";
	}

	/**
	 * 抽签接口
	 * @param trackDrawDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list")
	public Result<Page<TrackDrawDO>> list(TrackDrawDO trackDrawDTO){

		return trackDrawService.trackDrawList(trackDrawDTO);
	}

	/**
	 * 查询上次的抽签结果
	 */
	@ResponseBody
	@GetMapping("/trackList")
	public Result<Page<TrackDrawDO>> trackList(TrackDrawDO trackDrawDTO){

		return Result.ok(trackDrawService.trackList(trackDrawDTO));
	}

	/**
	 * 导出抽签结果信息
	 *
	 * @param response
	 */
	@Log("导出抽签结果信息")
	@RequestMapping("/downloadImportTemplate")
	@ResponseBody
	public void downloadImportTemplate(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
		Wrapper<TrackDrawDO> wrapper = new EntityWrapper<>();
		wrapper.orderBy(true,"sort");
		List<TrackDrawDO> trackDrawDOS = trackDrawService.selectList(wrapper);
		if (trackDrawDOS != null && trackDrawDOS.size() > 0) {
			//导出操作
			EasyPoiUtil.exportExcel(trackDrawDOS, "领队抽签信息导出", "领队抽签信息导出", TrackDrawDO.class,  "领队抽签信息导出", response);
		} else {
			throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
		}
	}



	@ApiOperation(value = "抽签列表分页查询接口", notes = "抽签列表分页查询接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current", value = "起始页", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer"),
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功",response = DecryptDO.class),
			@ApiResponse(code = 500, message = "服务器内部异常")})
	@ResponseBody
	@GetMapping(value = "/getTrack")
	public Result<Object> getTrack(Integer current,Integer size){
		return trackDrawService.getTrack(current,size);
	}


	@ApiOperation(value = "开始抽签接口", notes = "开始抽签接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current", value = "起始页", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer"),
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功",response = DecryptDO.class),
			@ApiResponse(code = 500, message = "服务器内部异常")})
	@ResponseBody
	@GetMapping(value = "/trackDraw")
	public Result<Object> trackDraw(Integer current,Integer size){
		return trackDrawService.trackDraw(current,size);
	}

	@ApiOperation(value = "抽签导出", notes = "抽签导出")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功",response = DecryptDO.class),
			@ApiResponse(code = 500, message = "服务器内部异常")})
	@ResponseBody
	@GetMapping(value = "/downloadImportTrackDraw")
	public void downloadImportTrackDraw(HttpServletResponse response,Integer current,Integer size){
		trackDrawService.downloadImportTrackDraw(response,current,size);
	}


	@ApiOperation(value = "清空抽签结果", notes = "清空抽签结果")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功",response = DecryptDO.class),
			@ApiResponse(code = 500, message = "服务器内部异常")})
	@ResponseBody
	@GetMapping(value = "/clearDraw")
	public Result<?> clearDraw(){
		careStuSignUpComRealityDao.clearDraw();

		return Result.ok();
	}

}
